<template>
	<!-- 诊疗数据识别存储 -->
	<view id="storage">
		<view class="nav">
			<text @click="navActive = 0">诊疗单列表</text>
			<text @click="navActive = 1">添加诊疗单</text>
		</view>
		<view class="list zldlist" v-if="navActive == 0">
			<view v-for="(item,index) in list" :key="index"  @click="listItem(item.id)">
				<image :src="item.image" mode="aspectFill"></image>
				<text>{{item.createtime}}</text>
			</view>
		</view>
		
		<block v-else>
			<view class="upload">
				<image :src="imgSrc" mode="widthFix"  @click="chooseImg"></image>
			</view>
			<view class="list">
				<view v-for="(item,index) in db" :key="index">{{item}}</view>
			</view>
			<view class="submit" @click="submit">确定</view>
		</block>
		
	</view>
</template>
<script>
	export default{
		data(){
			return{
				imgSrc:'',
				db:[],
				navActive:0,
				
				list:[],
			}
		},
		onLoad() {
			
		},
		onShow() {
			this.imgSrc = this.vuex_httpImageUrl+'static/index/upzld1.png'
			
			this.$u.post('/health/singlelst').then(res=>{
				console.log(res.data);
				let {list,count} = res.data

				this.list = list
			})
		},
		methods:{
			listItem(id){
				uni.navigateTo({
					url:'./detail?id='+id
				})
			},
			chooseImg(){
				uni.chooseImage({
					count:1,
					success:res=>{
						uni.showLoading({title:'上传中'})
						this.$u.utils.uploadFile(res.tempFilePaths[0]).then(res=>{
							let {all_image,image_id,thumb_image} = JSON.parse(res).data
							this.imgSrc = all_image
							uni.hideLoading()
							uni.showLoading({title:'识别中'})
							this.$u.post('/health/get_single',{image:all_image}).then(res=>{
								uni.hideLoading()
								this.db = res.data
							})
						})
					}
				})
			},
			submit(){
				if(this.imgSrc.indexOf('img.hexinle.top')>0){
					this.$u.toast('请选择诊疗单')
					return
				}
				uni.showLoading({title:'请稍等...'})
				this.$u.post('/health/add_singles',{
					image:this.imgSrc,
				}).then(res=>{
					uni.hideLoading()
					this.$u.toast(res.msg)
					setTimeout(_=>{
						uni.navigateBack()
					},700)
				})
			}
		},
		
	}
</script>
<style lang="scss">
	#storage{
		margin-top: 10rpx;
		overflow: hidden;
		
		.nav{
			width: 90%;
			margin: 20rpx auto;
			display: flex;
			justify-content: space-between;
			text{
				border-radius: 10rpx;
				text-align: center;
				width: 48%;
				color: #FFFFFF;
				background-color: rgba(36,118,228,.7);
				padding: 20rpx;
				cursor: pointer;
			}
		}
		.upload{
			overflow: hidden;
			background-color: #FFFFFF;
			image{
				display: block;
				width: 90%;
				margin:30rpx auto;
			}
		}
		
		>.list{
			padding: 0 40rpx;
			border-radius: 20rpx;
			width: 95%;
			margin: auto;
			background-color: #FFFFFF;
			margin-bottom: 20rpx;
			>view{
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 100rpx;
				border-bottom: 1px solid #F1F1F1;
			}
			.msg{
				margin-top: 30rpx;
				padding: 40rpx;
				height: auto;
				border-radius: 20rpx;
				background-color: #F8F8F8;
				border: 1px solid #EAEAEA;
			}
		}
		.zldlist{
			>view{
				justify-content: flex-start;
				image{
					width: 70rpx;
					height: 70rpx;
					border-radius: 10rpx;
					margin-right: 20rpx;
				}
			}
		}
		.submit{
			width: 80%;
			margin: 50rpx auto;
			text-align: center;
			padding: 20rpx;
			border-radius: 50rpx;
		}
	}
	
</style>